package 链表;

import java.util.HashMap;
import java.util.Map;

public class Solution83 {
    public static void main(String[] args) {
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(2, node1);
        ListNode node3 = new ListNode(6, node2);
        ListNode node4 = new ListNode(3, node3);
        ListNode node5 = new ListNode(2, node4);

        ListNode node11 = new ListNode(0);
        ListNode node12 = new ListNode(0, node11);

        ListNode node = deleteDuplicates(node12);
        System.out.println(node);

    }

    public static ListNode deleteDuplicates(ListNode head) {
        Map<Integer, ListNode> map = new HashMap<>();
        ListNode pre = new ListNode(-101);
        pre.next = head;
        ListNode before = pre;
        while (pre != null) {
            ListNode node = map.get(pre.val);
            if (node != null) {
                pre = before;
                pre.next = pre.next.next;
                pre = pre.next;

            } else {
                map.put(pre.val, pre);
                before = pre;
                pre = pre.next;
            }
        }
        return head;
    }
}
